<?php
include('./adm_header.php');
?>
			<div id="content">
				<?php
				if (isset($_POST['submit']))
				{
					if ($_POST['subpage'] == 'subpage')
					{
						// User wants page to be subpage.
						$title = str_replace(array('\\'), array(''), $_POST['title']);
						$body = str_replace(array('\\'), array(''), $_POST['body']);

						$fh = fopen('../pages/subpages/' . $_POST['title'], 'w');
						fwrite($fh, $_POST['body']);
						fclose($fh);
					}
					else
					{
						$body = str_replace(array('\\'), array(''), $_POST['body']);
						$title = str_replace(array('\\'), array(''), $_POST['title']);
						$order = $_POST['pageorder'];
						
						$fh = fopen('../pages/' . $_POST['pageorder'] . $_POST['title'], 'w');
						fwrite($fh, $_POST['body']);
						fclose($fh);
					}
					?>
					<meta http-equiv="refresh" content="0;url=./index.php" />
					<?php
					exit;
				}
				?>
				<p>When adding a page all HTML is enabled. If the page title and order number are the equivilent of an existing page the existing page will be overwritten. If the Subpage checkbox is selected the page will not be displayed on the Menu, therefore the "Page Order" box will be ignored.</p>
				<form action="addpage.php" method="post">
					<strong>Page Order:</strong><br />
					<input type="text" name="pageorder" style="width: 50px; font-family: Verdana; font-size; 12px;"><br />
					<strong>Subpage:</strong><input type="checkbox" name="subpage" value="subpage"><br /><br />
					<strong>Title:</strong><br />
					<input type="text" name="title" style="width: 600px; font-family: Verdana; font-size: 12px;"><br />
					<strong>Page Content:</strong><br />
					<textarea name="body" style="width: 600px; height: 400px; font-family: Verdana; font-size: 12px;"></textarea><br />
					<input type="submit" name="submit" value="Add">
				</form>
			</div>
		</div>
	</body>
</html>